import { createStore } from "redux";
import reducers from './reducers'
// import { thunk } from "redux-thunk";
import { applyMiddleware, logger, thunk, promise } from '../middleware'

// export default createStore(reducers);


// 中间件原理
// 重写dispatch方法，然后再调用原来的dispatch方法
// const store = createStore(reducers);
// let dispatch = store.dispatch;
// store.dispatch = function (action) {
//     console.log(store.getState());
//     dispatch(action);
//     console.log(store.getState());
//     return action;
// };
// export default store;
import createSagaMiddleware  from 'redux-saga' 
// import {helloSaga} from '../sagas';
import rootSaga  from '../sagas';
let sagaMiddleware = createSagaMiddleware()
// 使用中间件
// debugger
// const store = applyMiddleware(promise, thunk, logger)(createStore)(reducers)
const store = applyMiddleware(sagaMiddleware)(createStore)(reducers)
sagaMiddleware.run(rootSaga);
export default store;
